package com.ruoyi.repairCar.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.repairCar.domain.RescueRecord;
import com.ruoyi.repairCar.service.IRescueRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 救援记录Controller
 * 
 * @author ruoyi
 * @date 2025-03-21
 */
@RestController
@RequestMapping("/rescueRecord")
public class RescueRecordController extends BaseController
{
    @Autowired
    private IRescueRecordService rescueRecordService;

    /**
     * 查询救援记录列表
     */

    @GetMapping("/list")
    public TableDataInfo list(RescueRecord rescueRecord)
    {
        startPage();
        List<RescueRecord> list = rescueRecordService.selectRescueRecordList(rescueRecord);
        return getDataTable(list);
    }

    /**
     * 导出救援记录列表
     */

    @Log(title = "救援记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RescueRecord rescueRecord)
    {
        List<RescueRecord> list = rescueRecordService.selectRescueRecordList(rescueRecord);
        ExcelUtil<RescueRecord> util = new ExcelUtil<RescueRecord>(RescueRecord.class);
        util.exportExcel(response, list, "救援记录数据");
    }

    /**
     * 获取救援记录详细信息
     */

    @GetMapping(value = "/{rescueRecordId}")
    public AjaxResult getInfo(@PathVariable("rescueRecordId") Long rescueRecordId)
    {
        return success(rescueRecordService.selectRescueRecordByRescueRecordId(rescueRecordId));
    }

    /**
     * 新增救援记录
     */

    @Log(title = "救援记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RescueRecord rescueRecord)
    {
        return toAjax(rescueRecordService.insertRescueRecord(rescueRecord));
    }

    /**
     * 修改救援记录
     */

    @Log(title = "救援记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RescueRecord rescueRecord)
    {
        return toAjax(rescueRecordService.updateRescueRecord(rescueRecord));
    }

    /**
     * 删除救援记录
     */

    @Log(title = "救援记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rescueRecordIds}")
    public AjaxResult remove(@PathVariable Long[] rescueRecordIds)
    {
        return toAjax(rescueRecordService.deleteRescueRecordByRescueRecordIds(rescueRecordIds));
    }
}
